<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>随机选择</title>
</head>
<body>
      <h1></h1>
      <button onclick="starBtn(this)">开始</button>
      <button onclick="endBtn(this)">停止</button>

      <br/>

      <input style="margin-top:30px;" type="text">
      <button onclick="addBtn()">新增</button>

      <script>
           var arr = ['长城','北海','青岛','丽江','张家界','九寨沟','凤凰古城','庐山','黄龙'];
           var h1 = document.getElementsByTagName('h1')[0];
           var txt = document.getElementsByTagName('input')[0];
           var num,runner,sBtn;

           function randomArr(){
            num = Math.floor(Math.random()*arr.length);
            h1.innerHTML = arr[num];
           }
           //开始
           function starBtn(btn){
            runner = setInterval(randomArr,100);
            btn.disabled = true;
            sBtn = btn;
            console.log(btn);
           }

           //结束
           function endBtn(){
            clearInterval(runner);
            sBtn.disabled = false;
           }

           //添加
           function addBtn(){
            if(txt.value == ''){
                alert('请输入内容');
                return;
            }
            addArr = txt.value.split('|');

            for(var i in addArr){
                if(arr.indexOf(addArr[i])!=-1) {
                    alert('存在已有地点:'+addArr[i]);
                }else{
                    arr.push(addArr[i]);
                }
            }
                alert('新增成功');
                txt.value ='';
           }

           randomArr();
      </script>
</body>
</html>